<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>登陆</title>
		 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
         <meta name="apple-mobile-web-app-capable" content="yes">
         <meta content="yes" name="apple-touch-fullscreen">
         <meta name="apple-mobile-web-app-status-bar-style" content="black">
         <script src="js/add_js.js"></script>
	</head>
    <body>
    	 <div class="ball-pulse"><div></div><div></div><div></div></div>
    	<!--nav-->
        <nav class="bar bar-tab" style="display: none;">
             <a class="tab-item external active" href="home.html">我的</a>
             <a class="tab-item external" href="order.html">定单</a>
             <a class="tab-item external" href="carRental.html">出租</a>
             <a class="tab-item external" href="rentalCar.html">租车</a>
             <div class="clear"></div>
        </nav>
       <!--nav-->
       <div class="page content">
      	 <header class="bar bar-nav">
      	 	   <a class="button button-link button-nav pull-right active mm">登陆</a>
               <a class="button button-link button-nav pull-right yz">动态验证登陆</a>
               <a href="register.html"  class="button button-link button-nav pull-right external">注册 </a>
            </header>
      		<div class="login-list">
      			<ul>
      				<li><input class="c-border" type="text" placeholder="手机号" maxlength="11" name="phone" ></li>
      			    <li><input class="c-border login-list-mm" type="password" placeholder="登陆密码" title="1"  name="password"> </li> 
      			    <li><div class="c-border login-list-yz"><input class="c-border" type="text"  placeholder="输入验证码"><button class="bottn get-yz" >点击获取验证码</button><div class="clear"></div></div></li> 
      			   <!-- <li class="login-list-a"><a>忘记密码</a><a class="yz" disabled>短信验证登陆</a></li>-->
      			    <li class="login-list-b"><a class="bottn" id="dl">提交</a><div class="clear"></div></li> 
      			 </ul>
      	    </div>
      	<script>
      		$(document).ready(function(){
    			if(my.getCookie('token')!=''&&my.getCookie('id')!=''){
	               $.router.loadPage("home.html");
	              }else{
                  //获取key
      		      key=my.get_key(my.get_tokenSeed())
	            }
      			$('.bar-tab').css('display','none')
      			$('.ball-pulse').fadeOut()
      			
      			//表单选中效果切换
//    			$('.login-list input').focus(function(){
//    				$(this).css('color','#fff')
//    			})
//    			$('.login-list input').blur(function(){
//    				$(this).css('color','#5926BF')
//    			})
      			//验证登陆和账号登陆切换
      			$('.yz').click(function(){
      				
      				   $(this).siblings('a').removeClass('active')
      				   $(this).addClass('active')
      				   $('[name=password]').attr('title',2);
      				   $('.login-list input:eq(1)').val($(this).val())		
      				   $('.login-list-mm').toggle()
      				   $('.login-list-yz').toggle()
      			})
      			$('.mm').click(function(){
      				
      				   $(this).siblings('a').removeClass('active')
      				   $(this).addClass('active')
      				   $('[name=password]').attr('title',1);
      				   $('.login-list input:eq(1)').val($(this).val())		
      				   $('.login-list-mm').toggle()
      				   $('.login-list-yz').toggle()
      			})
      			//注册登陆点击效果
      			$('.login-list-b a').click(function(){ 
      				$(this).css({'color':'#fff','backgroundColor':'#5926BF'})
      			})
      			$('.login-list-yz input:eq(0)').change(function(){
      				$('.login-list input:eq(1)').val($(this).val())
      			})
      			//验证码获取
      			$('.get-yz').click(function(){//
      				my.countdown('10','.get-yz')
      				var u_phone={
      					u_mobile:$('.login-list input:eq(0)').val()
      				}
      				u_phone=my.cryptoASEencrypt(JSON.stringify(u_phone),key).toString()
      				$.ajax({
      					url:"http://192.168.1.10:8082/index.php?r=userabout%2Fmobilecode%2Fsendmobilecode",
      					type: 'post',
      					async:true,
      					data:{
      						'api_value':u_phone
      					},
      					error:function(){
      							$.toast("获取失败，请点击重新获取");
      						},
      					success:function(data){
      						if(data.match("err_code")!=null){	
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.setCookie('token',false,-1);
      									   my.setCookie('id',false,-1);
      									   $.alert("获取失败，请重新获取",function(){
      					                   $.router.reloadPage()
      				                       });
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}     
      							}else{
      							$.toast('验证码发送成功');
      							}
      					}
      				});
      			})
      			//验证电话
//    			$('.login-list input:eq(0)').blur(function(){
//    					$(this).val($(this).val().replace(/[^\d]/g,''))
//    					if($(this).val().length<11||$(this).val().length>11){
//    						 $.alert('请输入正确电话号码');
//    						//alert('请输入正确电话号码')
//    					}
//    					
//    				}
//    			)
      			//登陆提交
   			    $('#dl').click(function(){
      				$('.login-list input:eq(0)').val().replace(/[^\d]/g,'')
      				if($('.login-list input:eq(0)').val().length<11||$('.login-list input:eq(0)').val().length>11){
      					$.toast('请输入正确手机号码')
      					$('.login-list input:eq(0)').val('').focus()
      				}else if($('.login-list input:eq(1)').val().length<3){
      					switch($('[name=password]').attr('title'))
      								{
      									case '1':
      									   $.toast("请检查密码是否有误");
      									   $('.login-list input:eq(1)').val('').focus()
      									   break;
      									case '2':
      									   $.toast("验证码格式错误");
      									   $('.login-list input:eq(1)').val('').focus()
      									   break;
      									default:
      									   $.toast('请检查账号是否正确')
      								}
      				}else if(my.getCookie('token')==false){  //sessionStorage.token=='undefined'
      					$.toast('请检查账号密码是否正确')
      					$.router.reloadPage()
      				}else{
      					$.showIndicator()
      					var obj={
      						'u_account':$('[name=phone]').val(),
      						'u_password':$('[name=password]').val(),
      						'u_logintype':$('[name=password]').attr('title')
      					}
    					obj=JSON.stringify(obj)
                        obj=my.cryptoASEencrypt(obj,key).toString()
      					$.ajax({
      						type:"post",
      						url:"http://192.168.1.10:8082/index.php?r=userabout%2Fuser%2Fuserlogin",
      						data:{
      							'api_value':obj,
      						},
      						async:true,
      						error:function(){
      							$.hideIndicator()
      							$.toast("登陆失败，请重新登陆");
      							$.router.reloadPage()
      						},
      						success:function(data){
      							if(data.match("err_code")!=null){
      								$.hideIndicator()
      								switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.setCookie('token',false,-1);
      									   my.setCookie('id',false,-1);
      									   $.alert("登陆超时，请重新登陆",function(){
      					                   $.router.reloadPage()
      				                       });
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      									   $.router.reloadPage()
      								}
                                         
      							}else{
        								data=JSON.parse(my.cryptoASEdencrypt(data,key))
        								$.hideIndicator()
        								my.setCookie('id',data.user_id,1800)
        								//sessionStorage.load='1';//改变登陆状态
        								//sessionStorage.id=data.user_id//传递用户id
      							        $.router.loadPage("home.html");
      							        $('.bar-tab a').removeClass('active')
                                        $('.bar-tab a:eq(4)').addClass('active')
      							}
      						},
      					});
      				}
      			})
      		})
      	</script>
      </div>
	</body>
</html>
